package com.example.bailin.giftsay.me;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.bailin.giftsay.R;
import com.example.bailin.giftsay.entity.GuanZhuEntity;
import com.example.bailin.giftsay.tool.MyApp;
import com.example.bailin.giftsay.tool.NetTool;

import java.util.ArrayList;
import java.util.Collections;

/**
 * Created by bailin on 16/9/7.
 */
public class MeDpAdapter extends RecyclerView.Adapter<MeDpAdapter.MeDpViewHolder> {
    private ArrayList<GuanZhuEntity> guanZhuEntities;
    private int index;

    public void setIndex(int index) {
        this.index = index;
        notifyDataSetChanged();
    }

    public void setGuanZhuEntities(ArrayList<GuanZhuEntity> guanZhuEntities) {
        this.guanZhuEntities = guanZhuEntities;
        notifyDataSetChanged();
    }

    @Override
    public MeDpViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(MyApp.getContext()).inflate(R.layout.item_hot, parent, false);
        MeDpViewHolder viewHolder = new MeDpViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(MeDpViewHolder holder, int position) {
        Collections.sort(guanZhuEntities, new GuanZhuEntity());
        holder.tvHotName.setText(guanZhuEntities.get(position).getTitle());
        holder.tvHotCount.setText(guanZhuEntities.get(position).getCount());
        holder.tvHotPrice.setText(guanZhuEntities.get(position).getPrice());
        NetTool tool = new NetTool();
        tool.getImg(guanZhuEntities.get(position).getImgUrl(), holder.ivHotCoverImageUrl);
    }

    @Override
    public int getItemCount() {
        return index;
    }

    public class MeDpViewHolder extends RecyclerView.ViewHolder {
        private ImageView ivHotCoverImageUrl; // 大图片
        private TextView tvHotName; // 简单介绍
        private TextView tvHotPrice;// 价格
        private TextView tvHotCount; // 收藏次数
        public MeDpViewHolder(View itemView) {
            super(itemView);
            ivHotCoverImageUrl = (ImageView) itemView.findViewById(R.id.iv_hot_cover_image_url);
            tvHotName = (TextView) itemView.findViewById(R.id.tv_hot_name);
            tvHotPrice = (TextView) itemView.findViewById(R.id.tv_hot_price);
            tvHotCount = (TextView) itemView.findViewById(R.id.tv_hot_count);
        }
    }
}
